package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SwapFaceBatch;
import com.ruoyi.system.service.ISwapFaceBatchService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 批次换脸Controller
 * 
 * @author ruoyi
 * @date 2024-09-25
 */
@Controller
@RequestMapping("/system/batch")
public class SwapFaceBatchController extends BaseController
{
    private String prefix = "system/batch";

    @Autowired
    private ISwapFaceBatchService swapFaceBatchService;

    @RequiresPermissions("system:batch:view")
    @GetMapping()
    public String batch()
    {
        return prefix + "/batch";
    }

    /**
     * 查询批次换脸列表
     */
    @RequiresPermissions("system:batch:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SwapFaceBatch swapFaceBatch)
    {
        startPage();
        List<SwapFaceBatch> list = swapFaceBatchService.selectSwapFaceBatchList(swapFaceBatch);
        return getDataTable(list);
    }

    /**
     * 导出批次换脸列表
     */
    @RequiresPermissions("system:batch:export")
    @Log(title = "批次换脸", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SwapFaceBatch swapFaceBatch)
    {
        List<SwapFaceBatch> list = swapFaceBatchService.selectSwapFaceBatchList(swapFaceBatch);
        ExcelUtil<SwapFaceBatch> util = new ExcelUtil<SwapFaceBatch>(SwapFaceBatch.class);
        return util.exportExcel(list, "批次换脸数据");
    }

    /**
     * 新增批次换脸
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存批次换脸
     */
    @RequiresPermissions("system:batch:add")
    @Log(title = "批次换脸", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SwapFaceBatch swapFaceBatch)
    {
        return toAjax(swapFaceBatchService.insertSwapFaceBatch(swapFaceBatch));
    }

    /**
     * 修改批次换脸
     */
    @RequiresPermissions("system:batch:edit")
    @GetMapping("/edit/{batchId}")
    public String edit(@PathVariable("batchId") Long batchId, ModelMap mmap)
    {
        SwapFaceBatch swapFaceBatch = swapFaceBatchService.selectSwapFaceBatchByBatchId(batchId);
        mmap.put("swapFaceBatch", swapFaceBatch);
        return prefix + "/edit";
    }

    /**
     * 修改保存批次换脸
     */
    @RequiresPermissions("system:batch:edit")
    @Log(title = "批次换脸", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SwapFaceBatch swapFaceBatch)
    {
        return toAjax(swapFaceBatchService.updateSwapFaceBatch(swapFaceBatch));
    }

    /**
     * 删除批次换脸
     */
    @RequiresPermissions("system:batch:remove")
    @Log(title = "批次换脸", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(swapFaceBatchService.deleteSwapFaceBatchByBatchIds(ids));
    }
}
